package com.sw.haruka.view;


import android.content.Intent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;

import com.sw.haruka.R;
import com.sw.haruka.model.BaseActivity;
import com.sw.haruka.helper.utils.Configuration;
import com.sw.haruka.module.title.TitleMode;
import com.sw.haruka.module.title.TransformerTitleFragment;

public class SettingActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener {

    private Switch mExplorerAnimationOffset;
    private Switch mShowHiddenFileOffset;

    @Override
    protected int layoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.title_ll, new TransformerTitleFragment(TitleMode.SETTINGS_BAR))
                .commit();

        mExplorerAnimationOffset = findViewById(R.id.eao_offset);
        mExplorerAnimationOffset.setChecked(Configuration.INSTANCE.getBoolean(Configuration.Keys.ExplorerAnimationSwitch));
        mExplorerAnimationOffset.setOnCheckedChangeListener(this);

        mShowHiddenFileOffset = findViewById(R.id.shfo_offset);
        mShowHiddenFileOffset.setChecked(Configuration.INSTANCE.getBoolean(Configuration.Keys.ShowHiddenFile));
        mShowHiddenFileOffset.setOnCheckedChangeListener(this);
    }

    @Override
    protected void loadData(boolean isRefresh) {

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
//            case R.id.eao_offset:
//                eaoOperate(isChecked);
//                break;
//            case R.id.shfo_offset:
//                shfoOperate(isChecked);
//                break;
        }
        Toast.makeText(mContext, "重新打开APP后生效", Toast.LENGTH_SHORT).show();
    }

    private void shfoOperate(boolean isChecked) {
        Configuration.INSTANCE.saveBoolean(Configuration.Keys.ShowHiddenFile, isChecked);
    }

    private void eaoOperate(boolean isChecked) {
        Configuration.INSTANCE.saveBoolean(Configuration.Keys.ExplorerAnimationSwitch, isChecked);
    }


    public void manageCollections(View view) {
        startActivity(new Intent(this, ManageCollectionActivity.class));
    }

    public void explorerAnimationOffset(View view) {
        mExplorerAnimationOffset.performClick();
    }

    public void showHiddenFileOffset(View view) {
        mShowHiddenFileOffset.performClick();
    }

    public void finish(View view) {
        finish();
    }
}
